package dazuoye;

import java.util.*;

public class PlainTextSSFormatter implements SSFormatter{
	private static PlainTextSSFormatter singletonInstance = null;
    private PlainTextSSFormatter() { }
    public static PlainTextSSFormatter getSingletonInstance() {
        if (singletonInstance == null) {
            singletonInstance = new PlainTextSSFormatter();
        }
        return singletonInstance;
    }

    public String formatSS(ScoreSummary scoresummary){
        StringBuilder str=new StringBuilder();
        int sum=0;
        for (Iterator a=scoresummary.iterator();a.hasNext();){
            sum=sum+1;
            str=str.append("------------------------").append("\n"+"ScoreReport "+sum+"\n").append("generalscore-examscore-finalscore"+"\n");
            ScoreReport scorereport=(ScoreReport)a.next();
            for (Iterator b=scorereport.iterator();b.hasNext();){
                FinalScore finalscore=(FinalScore)b.next();
                ExamScore examscore=finalscore.getExamScore();
                str=str.append(examscore.getCode()+" ");
                str=str.append(examscore.getName()+" ");
                str=str.append(examscore.getSubject()+" ");
                str=str.append(finalscore.getGeneralScore()+" ");
                str=str.append(examscore.getScore()+" ");
                str=str.append(finalscore.getFinScore()+"\n");
            }
            str=str.append("number of scores: "+scorereport.getNumberOfFScores()+"\n");
        }
        return str.toString();
   }
}
